package com.lan.simplenavigation

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
import androidx.navigation.fragment.findNavController
import com.lan.simplenavigation.databinding.FragmentBlankBinding
import com.lan.simplenavigation.viewmodel.FavoriteViewModel

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
 * A simple [Fragment] subclass.
 * Use the [BlankFragment.newInstance] factory method to
 * create an instance of this fragment.
 */


private var _binding:FragmentBlankBinding? = null
private val binding get() = _binding!!

class BlankFragment : Fragment() {
    // TODO: Rename and change types of parameters
    private var param1: String? = null
    private var param2: String? = null




    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            param1 = it.getString(ARG_PARAM1)
            param2 = it.getString(ARG_PARAM2)
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        _binding = FragmentBlankBinding.inflate(inflater,container,false)

        return binding.root
    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        /*
      * 启用 Safe Args 后，该插件会生成代码，其中包含您定义的每个操作的类和方法。
      * 对于每个操作，Safe Args 还会为每个源目的地（生成相应操作的目的地）生成一个类。
      * 生成的类的名称由源目的地类的名称和“Directions”一词组成。例如，如果目的地的名称为 SpecifyAmountFragment，
      * 生成的类的名称为 SpecifyAmountFragmentDirections。生成的类为源目的地中定义的每个操作提供了一个静态方法。
      * 该方法会将任何定义的操作参数作为参数，并返回可传递到 navigate() 的 NavDirections 对象。
      *
      * */

        binding.bt1.setOnClickListener {
            val action = BlankFragmentDirections.actionBlankFragmentToBlankFragment2(
                    "Hi"+ binding.et1.text.toString(),"18")
            findNavController().navigate(action)
           // findNavController().navigate(R.id.action_blankFragment_to_blankFragment2)
            Toast.makeText(context,"go"+ binding.et1.text.toString(),Toast.LENGTH_SHORT).show()
        }

    }


    companion object {
        /**
         * Use this factory method to create a new instance of
         * this fragment using the provided parameters.
         *
         * @param param1 Parameter 1.
         * @param param2 Parameter 2.
         * @return A new instance of fragment BlankFragment.
         */
        // TODO: Rename and change types and number of parameters
        @JvmStatic
        fun newInstance(param1: String, param2: String) =
            BlankFragment().apply {
                arguments = Bundle().apply {
                    putString(ARG_PARAM1, param1)
                    putString(ARG_PARAM2, param2)
                }
            }
    }
}